package com.tiankun.eurekausermsg.controller;

import com.tiankun.eurekausermsg.mapper.UserMapper;
import com.tiankun.eurekausermsg.service.UserService;
import com.tiankun.eurekausermsg.util.MD5Util;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author 杨天可
 * @Date 2020/11/10 10:18
 * @Version 1.0
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    UserMapper userMapper;

    //项目测试
    @RequestMapping("hello")
    @ResponseBody
    public String hello() {
       return "success";
    }

    //连接数据库测试
    @RequestMapping("/find")
    @ResponseBody
    public Map find(){
        return userMapper.find();
    }

    @Resource
    UserService userService;

    //用户注册
    @PostMapping("/regist")
    @ResponseBody
    public Map regist(@RequestBody Map map){
        String  password = (String) map.get("password");
        String  phone = (String) map.get("phone");
        String  yzm = (String) map.get("yzm");
        return userService.insert(phone, password, yzm);
    }

    //用户登录
    @PostMapping("/login")
    @ResponseBody
    public Map login(@RequestBody Map map){
        String phone =(String) map.get("phone");
        String password =(String) map.get("password");
        return userService.login(phone,password);
    }

    //忘记密码
    @PostMapping("/changepwd")
    @ResponseBody
    public Map changepwd(@RequestBody Map map){
        String  password = (String) map.get("password");
        String  phone = (String) map.get("phone");
        String  yzm = (String) map.get("yzm");
        return  userService.changepwd(password,phone,yzm);
    }
}
